Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for HPA dry-run metrics duplication #207

Merged
merged 1 commit into from
Jan 6, 2022
Merged

Conversation

stefanprodan
Copy link
Member

@stefanprodan stefanprodan commented Jan 5, 2022

This PR implements a workaround for a Kubernetes API server-side apply dry-run bug where it duplicates the first item in the metrics array and inserts an empty metric as the last item in the array.

Given:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: frontend
  namespace: default
spec:
  behavior:
    scaleDown:
      policies:
        - periodSeconds: 15
          type: Percent
          value: 100
      selectPolicy: Max
      stabilizationWindowSeconds: 60
    scaleUp:
      policies:
        - periodSeconds: 15
          type: Pods
          value: 4
        - periodSeconds: 15
          type: Percent
          value: 100
      selectPolicy: Max
      stabilizationWindowSeconds: 0
  maxReplicas: 30
  metrics:
    - type: Pods
      pods:
        metric:
          name: nginx_http_requests_total
        target:
          averageValue: "4"
          type: AverageValue
  minReplicas: 2
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: frontend

The dry-run diff returns bogus data:

$ kubectl diff --server-side -f hpa.yaml
@@ -74,6 +97,13 @@
         averageValue: "4"
         type: AverageValue
     type: Pods
+  - pods:
+      metric:
+        name: nginx_http_requests_total
+      target:
+        averageValue: "4"
+        type: AverageValue
+    type: Pods

This gets even worse if you have two metrics, now an empty metric is added by the Kubernetes API:

$ kubectl diff --server-side -f hpa.yaml
+  - pods:
+      metric:
+        name: nginx_http_requests_total
+      target:
+        averageValue: "4"
+        type: AverageValue
+    type: Pods
+  - type: ""

Ref: fluxcd/kustomize-controller#494

@stefanprodan stefanprodan added the area/server-side-apply SSA related issues and pull requests label Jan 5, 2022
@stefanprodan stefanprodan force-pushed the ssa-hpa-diff branch 4 times, most recently from dbebbc8 to 1db33d7 Compare January 5, 2022 23:11
Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/server-side-apply SSA related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants